import cloneDeep from 'lodash/cloneDeep'

export const createDefaultPostProcessingConfig = () =>
  cloneDeep({
    enabled: false,
    sao: {
      enabled: false,
      intensity: 1,
      diffusion: 80
    },
    fxaa: {
      enabled: false
    },
    dof: {
      enabled: false
    },
    bloom: {
      enabled: false,
      intensity: 2.5,
      radius: 0.6,
      threshold: 0.1,
      exposure: 1
    },
    selectiveBloom: {
      enabled: false,
      intensity: 2,
      radius: 0
    },
    ssr: {
      enabled: false,
      intensity: 0.5,
      distance: 0.2
    }
  })

export const ensurePostProcessingConfig = (config?: any) => {
  const defaults = createDefaultPostProcessingConfig()
  if (!config) return defaults

  return {
    ...defaults,
    ...config,
    sao: { ...defaults.sao, ...(config.sao || {}) },
    fxaa: { ...defaults.fxaa, ...(config.fxaa || {}) },
    dof: { ...defaults.dof, ...(config.dof || {}) },
    bloom: { ...defaults.bloom, ...(config.bloom || {}) },
    selectiveBloom: { ...defaults.selectiveBloom, ...(config.selectiveBloom || {}) },
    ssr: { ...defaults.ssr, ...(config.ssr || {}) }
  }
}
